From f1f5c0ba12b34b6e103ccaddb5dc7885fe806c40 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 16 Nov 2005 12:36:47 +0100 Subject: [PATCH] Review checks for Error string when checking that bad arguments are handled correctly. Many checks were looking using output.find("Error") > 1, which is incorrect, as we do not guarantee that the word "Error" will be first in the output (never mind the fact that strings are indexed from 0). All these checks have been changed to compare against -1. In particular, this should fix the failure of create_noparm_neg and create_badparm_neg on a machine with the /etc/xen/xmdefconfig file in place, as xm create issues the Using config file "/etc/xen/xmdefconfig" diagnostic before reporting the error. Signed-off-by: Ewan Mellor --- .../block-create/06_block_attach_baddomain_neg.py | 2 +- .../block-create/07_block_attach_baddevice_neg.py | 2 +- .../block-create/08_block_attach_bad_filedevice_neg.py | 2 +- tools/xm-test/tests/console/01_console_badopt_neg.py | 2 +- tools/xm-test/tests/console/02_console_baddom_neg.py | 4 ++-- tools/xm-test/tests/create/02_create_noparm_neg.py | 2 +- tools/xm-test/tests/create/03_create_badparm_neg.py | 2 +- .../xm-test/tests/create/05_create_noroot_noram_neg.py | 2 +- tools/xm-test/tests/destroy/02_destroy_noparm_neg.py | 2 +- tools/xm-test/tests/destroy/03_destroy_nonexist_neg.py | 2 +- tools/xm-test/tests/destroy/04_destroy_badparm_neg.py | 2 +- tools/xm-test/tests/dmesg/02_dmesg_basic_neg.py | 2 +- tools/xm-test/tests/help/01_help_basic_pos.py | 2 +- tools/xm-test/tests/help/02_help_basic_neg.py | 2 +- tools/xm-test/tests/help/03_help_badparm_neg.py | 2 +- tools/xm-test/tests/help/05_help_nonroot_pos.py | 2 +- tools/xm-test/tests/list/02_list_badparm_neg.py | 2 +- tools/xm-test/tests/list/03_list_nonexist_neg.py | 2 +- tools/xm-test/tests/list/06_list_nonroot.py | 2 +- tools/xm-test/tests/memset/02_memset_badparm_neg.py | 10 +++++----- tools/xm-test/tests/pause/02_pause_badopt_neg.py | 2 +- tools/xm-test/tests/pause/03_pause_badname_neg.py | 2 +- tools/xm-test/tests/pause/04_pause_badid_neg.py | 2 +- tools/xm-test/tests/reboot/02_reboot_badopt_neg.py | 2 +- tools/xm-test/tests/reboot/03_reboot_badname_neg.py | 2 +- tools/xm-test/tests/restore/02_restore_badparm_neg.py | 2 +- .../tests/restore/03_restore_badfilename_neg.py | 2 +- tools/xm-test/tests/save/02_save_badparm_neg.py | 2 +- tools/xm-test/tests/save/03_save_bogusfile_neg.py | 2 +- .../xm-test/tests/shutdown/02_shutdown_badparm_neg.py | 2 +- .../xm-test/tests/shutdown/03_shutdown_nonexist_neg.py | 2 +- 31 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py b/tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py index cc6746d47d..856b7c0f57 100644 --- a/tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py +++ b/tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py @@ -11,7 +11,7 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status ) -elif where > 1: +elif where == -1: FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output ) diff --git a/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py b/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py index 930b9c1300..0d388a5bac 100644 --- a/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py +++ b/tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py @@ -42,7 +42,7 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status ) -elif where > 1: +elif where == -1: FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output ) try: diff --git a/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py b/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py index 50073037be..2420fec3ba 100644 --- a/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py +++ b/tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py @@ -41,7 +41,7 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm block-attach returned bad status, expected non 0, status is: %i" % status ) -elif where > 1: +elif where == -1: FAIL("xm block-attach returned bad output, expected Error, output is: %s" % output ) try: diff --git a/tools/xm-test/tests/console/01_console_badopt_neg.py b/tools/xm-test/tests/console/01_console_badopt_neg.py index 0fa8f8384e..1c00afef4f 100644 --- a/tools/xm-test/tests/console/01_console_badopt_neg.py +++ b/tools/xm-test/tests/console/01_console_badopt_neg.py @@ -17,5 +17,5 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm console returned invalid %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm console didn't report error on bad argument") diff --git a/tools/xm-test/tests/console/02_console_baddom_neg.py b/tools/xm-test/tests/console/02_console_baddom_neg.py index 217dadfc13..56bf1a0451 100644 --- a/tools/xm-test/tests/console/02_console_baddom_neg.py +++ b/tools/xm-test/tests/console/02_console_baddom_neg.py @@ -15,7 +15,7 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm console returned invalid %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm console failed to report error on bad domid") status, output = traceCommand("xm console NON_EXIST") @@ -23,5 +23,5 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm console returned invalid %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm console failed to report error on bad domname") diff --git a/tools/xm-test/tests/create/02_create_noparm_neg.py b/tools/xm-test/tests/create/02_create_noparm_neg.py index 7d6a85a5fb..54f882853c 100644 --- a/tools/xm-test/tests/create/02_create_noparm_neg.py +++ b/tools/xm-test/tests/create/02_create_noparm_neg.py @@ -12,6 +12,6 @@ eyecatcher = "Error:" where = output.find(eyecatcher) if status == 0: FAIL("xm create returned invalid %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm create failed to report error on missing args") diff --git a/tools/xm-test/tests/create/03_create_badparm_neg.py b/tools/xm-test/tests/create/03_create_badparm_neg.py index 68cfeb6eb9..2a64cf3305 100644 --- a/tools/xm-test/tests/create/03_create_badparm_neg.py +++ b/tools/xm-test/tests/create/03_create_badparm_neg.py @@ -15,5 +15,5 @@ from XmTestLib import * status, output = traceCommand("xm create -x") eyecatcher = "Error:" where = output.find(eyecatcher) -if where != 0: +if where == -1: FAIL("xm create failed to report error on bad arg") diff --git a/tools/xm-test/tests/create/05_create_noroot_noram_neg.py b/tools/xm-test/tests/create/05_create_noroot_noram_neg.py index 8e92a5412c..b6756c633d 100644 --- a/tools/xm-test/tests/create/05_create_noroot_noram_neg.py +++ b/tools/xm-test/tests/create/05_create_noroot_noram_neg.py @@ -22,5 +22,5 @@ time.sleep(15) eyecatcher = "NOROOT" status, output = traceCommand("xm list") where = output.find(eyecatcher) -if where != -1 : +if where != -1: FAIL("xm create test05 passed with no root and no ramdisk. Expected result: Fail.") diff --git a/tools/xm-test/tests/destroy/02_destroy_noparm_neg.py b/tools/xm-test/tests/destroy/02_destroy_noparm_neg.py index 3a634053c5..8fadb1eced 100644 --- a/tools/xm-test/tests/destroy/02_destroy_noparm_neg.py +++ b/tools/xm-test/tests/destroy/02_destroy_noparm_neg.py @@ -12,5 +12,5 @@ eyecatcher = "Error:" where = output.find(eyecatcher) if status == 0: FAIL("xm destroy returned invalid %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm destroy failed to report error for missing arg") diff --git a/tools/xm-test/tests/destroy/03_destroy_nonexist_neg.py b/tools/xm-test/tests/destroy/03_destroy_nonexist_neg.py index 0c77347f3d..9520a65e2b 100644 --- a/tools/xm-test/tests/destroy/03_destroy_nonexist_neg.py +++ b/tools/xm-test/tests/destroy/03_destroy_nonexist_neg.py @@ -12,5 +12,5 @@ eyecatcher = "Error:" where = output.find(eyecatcher) if status == 0: FAIL("xm destroy returned invalid %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm destroy failed to report error for bad arg") diff --git a/tools/xm-test/tests/destroy/04_destroy_badparm_neg.py b/tools/xm-test/tests/destroy/04_destroy_badparm_neg.py index 5814195c0d..179b4d0c36 100644 --- a/tools/xm-test/tests/destroy/04_destroy_badparm_neg.py +++ b/tools/xm-test/tests/destroy/04_destroy_badparm_neg.py @@ -12,5 +12,5 @@ eyecatcher = "Error:" where = output.find(eyecatcher) if status == 0: FAIL("xm destroy returned invalid %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm destroy failed to report error for bad domid") diff --git a/tools/xm-test/tests/dmesg/02_dmesg_basic_neg.py b/tools/xm-test/tests/dmesg/02_dmesg_basic_neg.py index 10cd7a7cfd..e074c0d16a 100644 --- a/tools/xm-test/tests/dmesg/02_dmesg_basic_neg.py +++ b/tools/xm-test/tests/dmesg/02_dmesg_basic_neg.py @@ -12,6 +12,6 @@ eyecatcher = "Error:" where = output.find(eyecatcher) if status == 0: FAIL("xm dmesg returned invalid %i != 0" % status) -elif where == 1: +elif where == -1: FAIL("xm dmesg failed to report error for bad arg") diff --git a/tools/xm-test/tests/help/01_help_basic_pos.py b/tools/xm-test/tests/help/01_help_basic_pos.py index b7162a5f52..11b84f06b7 100644 --- a/tools/xm-test/tests/help/01_help_basic_pos.py +++ b/tools/xm-test/tests/help/01_help_basic_pos.py @@ -10,5 +10,5 @@ from XmTestLib import * status, output = traceCommand("xm help") eyecatcher = "Usage:" where = output.find(eyecatcher) -if where != 0: +if where == -1: FAIL("xm help: didn't see the usage string") diff --git a/tools/xm-test/tests/help/02_help_basic_neg.py b/tools/xm-test/tests/help/02_help_basic_neg.py index 28b2a07a10..09116ab2c0 100644 --- a/tools/xm-test/tests/help/02_help_basic_neg.py +++ b/tools/xm-test/tests/help/02_help_basic_neg.py @@ -10,5 +10,5 @@ from XmTestLib import * status, output = traceCommand("xm") eyecatcher = "Usage:" where = output.find(eyecatcher) -if where != 0: +if where == -1: FAIL("xm: didn't display usage when given no arguments") diff --git a/tools/xm-test/tests/help/03_help_badparm_neg.py b/tools/xm-test/tests/help/03_help_badparm_neg.py index 1c9cd62606..1064a755a3 100644 --- a/tools/xm-test/tests/help/03_help_badparm_neg.py +++ b/tools/xm-test/tests/help/03_help_badparm_neg.py @@ -10,5 +10,5 @@ from XmTestLib import * status, output = traceCommand("xm -x") eyecatcher = "Error:" where = output.find(eyecatcher) -if where != 0: +if where == -1: FAIL("xm failed to report error for bad arg") diff --git a/tools/xm-test/tests/help/05_help_nonroot_pos.py b/tools/xm-test/tests/help/05_help_nonroot_pos.py index 9798735c1e..87a395f62f 100644 --- a/tools/xm-test/tests/help/05_help_nonroot_pos.py +++ b/tools/xm-test/tests/help/05_help_nonroot_pos.py @@ -13,5 +13,5 @@ becomeNonRoot() status, output = traceCommand("xm help") eyecatcher = "Usage:" where = output.find(eyecatcher) -if where != 0: +if where == -1: FAIL("xm help: didn't see the usage string") diff --git a/tools/xm-test/tests/list/02_list_badparm_neg.py b/tools/xm-test/tests/list/02_list_badparm_neg.py index f018e5c20e..5c40694b93 100644 --- a/tools/xm-test/tests/list/02_list_badparm_neg.py +++ b/tools/xm-test/tests/list/02_list_badparm_neg.py @@ -12,5 +12,5 @@ eyecatcher = "Error:" where = output.find(eyecatcher) if status == 0: FAIL("xm list returned invalud %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm list failed to report error for bad arg") diff --git a/tools/xm-test/tests/list/03_list_nonexist_neg.py b/tools/xm-test/tests/list/03_list_nonexist_neg.py index db3175fb87..04acbd6b9c 100644 --- a/tools/xm-test/tests/list/03_list_nonexist_neg.py +++ b/tools/xm-test/tests/list/03_list_nonexist_neg.py @@ -12,6 +12,6 @@ eyecatcher = "Error:" where = output.find(eyecatcher) if status == 0: FAIL("xm list returned invalid %i != 0" % status) -elif where > 1: +elif where == -1: FAIL("xm list failed to report error for invalid domid") diff --git a/tools/xm-test/tests/list/06_list_nonroot.py b/tools/xm-test/tests/list/06_list_nonroot.py index 7b61508cb7..c10ac56da8 100644 --- a/tools/xm-test/tests/list/06_list_nonroot.py +++ b/tools/xm-test/tests/list/06_list_nonroot.py @@ -11,5 +11,5 @@ becomeNonRoot() status, output = traceCommand("xm list") eyecatcher = "Error: Most commands need root access" where = output.find(eyecatcher) -if where != 0: +if where == -1: FAIL("xm help: didn't see the root hint, saw %s" % output) diff --git a/tools/xm-test/tests/memset/02_memset_badparm_neg.py b/tools/xm-test/tests/memset/02_memset_badparm_neg.py index f2b9e788e0..07f7e2c635 100644 --- a/tools/xm-test/tests/memset/02_memset_badparm_neg.py +++ b/tools/xm-test/tests/memset/02_memset_badparm_neg.py @@ -24,7 +24,7 @@ eyecatcher = "Error:" where = output.find(eyecatcher) if status == 0: FAIL("xm mem-set returned invalid %i == 0" % status) -elif where > 1: +elif where == -1: FAIL("xm mem-set failed to report error for missing arg") # destroy non existent parm input - negative test @@ -32,7 +32,7 @@ status, output = traceCommand("xm mem-set -x") where = output.find(eyecatcher) if status == 0: FAIL("xm mem-set returned invalid %i == 0" % status) -elif where != 0: +elif where == -1: FAIL("xm mem-set failed to report error for bad arg") # destroy non existent domain - negative test @@ -40,14 +40,14 @@ status, output = traceCommand("xm mem-set 6666") where = output.find(eyecatcher) if status == 0: FAIL("xm mem-set returned invalid %i == 0" % status) -elif where != 0: +elif where == -1: FAIL("xm mem-set failed to report error for invalid domid") # destroy non existent domain and memory - negative test status, output = traceCommand("xm mem-set 6666 64") where = output.find(eyecatcher) if status == 0: - FAIL("xm mem-set returned invalid %i != 0" % status) -elif where != 0: + FAIL("xm mem-set returned invalid %i == -1" % status) +elif where == -1: FAIL("xm mem-set failed to report error for invalid domid") diff --git a/tools/xm-test/tests/pause/02_pause_badopt_neg.py b/tools/xm-test/tests/pause/02_pause_badopt_neg.py index 4d504d1d92..18eda67641 100644 --- a/tools/xm-test/tests/pause/02_pause_badopt_neg.py +++ b/tools/xm-test/tests/pause/02_pause_badopt_neg.py @@ -25,7 +25,7 @@ where = output.find(eyecatcher) if status == 0: domain.destroy() FAIL("xm pause returned bad status, expected non 0, status is: %i" % status ) -elif where > 1: +elif where == -1: domain.destroy() FAIL("xm pause returned bad output, expected Error, output is: %s" % output ) diff --git a/tools/xm-test/tests/pause/03_pause_badname_neg.py b/tools/xm-test/tests/pause/03_pause_badname_neg.py index 7ec1bc4109..982034c66b 100644 --- a/tools/xm-test/tests/pause/03_pause_badname_neg.py +++ b/tools/xm-test/tests/pause/03_pause_badname_neg.py @@ -14,5 +14,5 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm pause returned bad status, expected non 0, status is: %i" % status ) -elif where > 1: +elif where == -1: FAIL("xm pause returned bad output, expected Error, output is: %s" % output ) diff --git a/tools/xm-test/tests/pause/04_pause_badid_neg.py b/tools/xm-test/tests/pause/04_pause_badid_neg.py index c5bd578500..ffd1be2168 100644 --- a/tools/xm-test/tests/pause/04_pause_badid_neg.py +++ b/tools/xm-test/tests/pause/04_pause_badid_neg.py @@ -14,5 +14,5 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm pause returned bad status, expected non 0, status is: %i" % status ) -elif where > 1: +elif where == -1: FAIL("xm pause returned bad output, expected Error, output is: %s" % output ) diff --git a/tools/xm-test/tests/reboot/02_reboot_badopt_neg.py b/tools/xm-test/tests/reboot/02_reboot_badopt_neg.py index cfcd52c021..b0a23bb4a5 100644 --- a/tools/xm-test/tests/reboot/02_reboot_badopt_neg.py +++ b/tools/xm-test/tests/reboot/02_reboot_badopt_neg.py @@ -25,7 +25,7 @@ where = output.find(eyecatcher) if status == 0: domain.destroy() FAIL("xm reboot returned invalid %i == 0" % status ) -elif where > 1: +elif where == -1: domain.destroy() FAIL("xm reboot failed to report error for bad arg") diff --git a/tools/xm-test/tests/reboot/03_reboot_badname_neg.py b/tools/xm-test/tests/reboot/03_reboot_badname_neg.py index aa1aabb6e0..480e5dd398 100644 --- a/tools/xm-test/tests/reboot/03_reboot_badname_neg.py +++ b/tools/xm-test/tests/reboot/03_reboot_badname_neg.py @@ -14,5 +14,5 @@ eyecatcher = "Error" where = output.find(eyecatcher) if status == 0: FAIL("xm reboot returned invalid %i == 0" % status ) -elif where > 1: +elif where == -1: FAIL("xm reboot failed to report error for non-existent domain" ) diff --git a/tools/xm-test/tests/restore/02_restore_badparm_neg.py b/tools/xm-test/tests/restore/02_restore_badparm_neg.py index 6f1a5da079..aee5b5da72 100644 --- a/tools/xm-test/tests/restore/02_restore_badparm_neg.py +++ b/tools/xm-test/tests/restore/02_restore_badparm_neg.py @@ -21,5 +21,5 @@ if status == 0: FAIL("xm restore returned bad status, expected non 0, status is: %i" % status) elif where2 == 0: FAIL("xm restore returned a stack dump, expected nice error message") -elif where1 > 0: +elif where1 == -1: FAIL("xm restore returned bad output, expected Error:, output is: %s" % output) diff --git a/tools/xm-test/tests/restore/03_restore_badfilename_neg.py b/tools/xm-test/tests/restore/03_restore_badfilename_neg.py index 9a35cc3ae1..7639c4b90e 100644 --- a/tools/xm-test/tests/restore/03_restore_badfilename_neg.py +++ b/tools/xm-test/tests/restore/03_restore_badfilename_neg.py @@ -21,5 +21,5 @@ if status == 0: FAIL("xm restore returned bad status, expected non 0, status is: %i" % status) elif where2 == 0: FAIL("xm restore returned a stack dump, expected nice error message") -elif where1 > 0: +elif where1 == -1: FAIL("xm restore returned bad output, expected Error:, output is: %s" % output) diff --git a/tools/xm-test/tests/save/02_save_badparm_neg.py b/tools/xm-test/tests/save/02_save_badparm_neg.py index 5d81c75183..7966ff1ee1 100644 --- a/tools/xm-test/tests/save/02_save_badparm_neg.py +++ b/tools/xm-test/tests/save/02_save_badparm_neg.py @@ -21,5 +21,5 @@ if status == 0: FAIL("xm save returned bad status, expected non 0, status is: %i" % status) elif where2 == 0: FAIL("xm save returned a stack dump, expected nice error message") -elif where1 > 0: +elif where1 == -1: FAIL("xm save returned bad output, expected Error:, output is: %s" % output) diff --git a/tools/xm-test/tests/save/03_save_bogusfile_neg.py b/tools/xm-test/tests/save/03_save_bogusfile_neg.py index 4f1d042f42..de66e6080f 100644 --- a/tools/xm-test/tests/save/03_save_bogusfile_neg.py +++ b/tools/xm-test/tests/save/03_save_bogusfile_neg.py @@ -38,5 +38,5 @@ if status == 0: FAIL("xm save returned bad status, expected non 0, status is: %i" % status) elif where1 == 0: FAIL("xm save returned a stack dump, expected nice error message") -elif where2 > 0: +elif where2 == -1: FAIL("xm save returned bad output, expected Error:, output is: %s" % output) diff --git a/tools/xm-test/tests/shutdown/02_shutdown_badparm_neg.py b/tools/xm-test/tests/shutdown/02_shutdown_badparm_neg.py index 34e5c23d3f..8ec2a5b3c2 100644 --- a/tools/xm-test/tests/shutdown/02_shutdown_badparm_neg.py +++ b/tools/xm-test/tests/shutdown/02_shutdown_badparm_neg.py @@ -32,7 +32,7 @@ ret, output = traceCommand("xm shutdown -x %s" % domain.getName()) where = output.find(eyecatcher) if (ret == 0): FAIL("xm shutdown returned invalid %i == 0" % ret) -elif where != 0: +elif where == -1: FAIL("xm shutdown failed to report error for bad arg") # Stop the domain (nice shutdown) diff --git a/tools/xm-test/tests/shutdown/03_shutdown_nonexist_neg.py b/tools/xm-test/tests/shutdown/03_shutdown_nonexist_neg.py index 160ecdcdc2..4998911d88 100644 --- a/tools/xm-test/tests/shutdown/03_shutdown_nonexist_neg.py +++ b/tools/xm-test/tests/shutdown/03_shutdown_nonexist_neg.py @@ -18,5 +18,5 @@ ret, output = traceCommand("xm shutdown 9999") where = output.find(eyecatcher) if (ret == 0): FAIL("xm shutdown returned invalid %i == 0" % ret) -elif where != 0: +elif where == -1: FAIL("xm shutdown failed to report error for bad domid") -- 2.30.2